<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\dao\car;


use app\dao\BaseDao;
use app\model\car\CarOrderDetail;

class CarOrderDetailDao extends BaseDao
{
    protected function setModel(): string
    {
        return CarOrderDetail::class;
    }

    /**
     * 列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @return array
     */
    public function getList(array $where = [],int $page, int $limit){
        $model = $this->getModel()->alias('d');
        $model->join('car_order o','o.id=d.order_id','left');
        $model->field('d.*,o.order_no');
        $model = $this->setWheres($model,$where);
        $count = $model->count();
        $list = $model->page($page,$limit)->order('id desc')->select()->toArray();
        return compact('list','count');
    }

    /**
     * 搜索条件
     * @param $model
     * @param $where
     * @return mixed
     */
    public function setWheres($model,$where){
        if(isset($where['fee_type']) && $where['fee_type']){
            $model->where('d.fee_type',$where['fee_type']);
        }
        if(isset($where['order_no']) && $where['order_no']){
            $model->where('o.order_no','like',"%{$where['order_no']}%");
        }
        return $model;
    }
}
